﻿Imports System.Data
Imports VSModel
Imports SecurityService
Imports Cls_Common
Partial Class Control_VBPQSigner_Create
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "duyjs", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "duyjs", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
        End If
    End Sub
#End Region
#Region "Event for control "
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Using data As New VSEntities
            'Kiem tra CQBH da ton tai chua
            Dim q = (From p In data.VBPQNguoiKies Where p.NguoiKy.ToUpper = txtSigner.Text.Trim.ToUpper Select p).FirstOrDefault
            If (q Is Nothing) Then
                Try
                    Dim sb As New VBPQNguoiKy
                    sb.NguoiKy = txtSigner.Text.Trim
                    data.VBPQNguoiKies.AddObject(sb)
                    data.SaveChanges()
                    AddKeyWordJavascript(txtSigner.Text)

                    sb = Nothing
                    Insert_App_Log("Insert subject:" & txtSigner.Text.Trim & "", Function_Name.Subject, Audit_Type.Create, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                    'Excute_Javascript("Alertbox('Thêm mới cơ quan ban hành thành công.');", Me.Page, True)
                    Dim strMessage As String = ""
                    '"Alertbox('Cập nhật dữ liệu thành công.');"
                    strMessage &= "window.parent.setVBPQValue();"
                    strMessage &= "self.parent.tb_remove();"
                    Excute_Javascript(strMessage, Page, True)
                Catch ex As Exception
                    log4net.Config.XmlConfigurator.Configure()
                    log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                    Excute_Javascript("Alertbox('Thêm mới chữ ký thất bại.');", Me.Page, True)
                End Try
            Else
                showError.Visible = True
            End If
        End Using
    End Sub
    Protected Sub btnHuy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Response.Redirect("List.aspx")
    End Sub
#End Region
End Class
